package com.zr.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.BaseDao;
import com.zr.dao.UserDao;
import com.zr.model.TRole;
import com.zr.model.TUser;
import com.zr.service.UserService;

import net.sf.json.JSONObject;
@Service("userService")
public class UserServiceImpl implements  UserService{
    //
	@Resource
	private BaseDao<TUser>  baseDao;
	@Resource
	private  UserDao<TUser>  userDao;
	@Override
	public TUser findUserByuserNameanduserPsw(TUser user) {
		// TODO Auto-generated method stub
		String hql = "from TUser u where u.uacount=? and u.upassword=?";
		return baseDao.get(hql,new Object[]{user.getUacount(),user.getUpassword()});
	}
	@Override
	public JSONObject findUserMsg(int page, int rows) {
		// TODO Auto-generated method stub
		JSONObject  obj  = new JSONObject();
		obj.put("total", userDao.findUserCount());
		obj.put("rows", userDao.findUserMsg(page, rows));
		return obj;
	}
	@Override
	public Boolean addUser(String uacount, String upassword, String uname,int rid) {
		// TODO Auto-generated method stub
		TRole role=userDao.selectRole(rid);
		return userDao.adduser(uacount, upassword, uname,role);
	}
	@Override
	public Boolean deleteUser(int rid) {
		// TODO Auto-generated method stub
		return userDao.deleteUser(rid);
	}
	@Override
	public Boolean updateUser(int uid, String uacount, String upassword, String uname, int rid) {
		// TODO Auto-generated method stub
		TRole role=userDao.selectRole(rid);
		return userDao.updateUser(uid, uacount, upassword, uname, role);
	}

}
